package com.canyou.system.entity.user;

import com.canyou.operlog.DataMap;
import com.canyou.operlog.DataMaps;
import com.canyou.operlog.DateFormat;
import com.canyou.utils.RegexUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import org.hibernate.validator.constraints.Range;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import java.time.ZonedDateTime;
import java.util.List;

/**
 * 用户新增编辑模型
 *
 * @author fy
 * @date 2021/5/20 11:44
 */
@Data
@Accessors(chain = true)
@ApiModel(value = "UserDTO", description = "用户新增编辑模型")
public class UserDTO {

    @ApiModelProperty(value = "主键id")
    private Long id;

    @ApiModelProperty("用户名")
    @NotBlank(message = "用户名不能为空")
    @Pattern(regexp = RegexUtils.USER_NAME, message = "用户名必须为5-11位的数字字母组成")
    private String username;

    @ApiModelProperty("手机号码")
    @NotBlank(message = "手机号码不能为空")
    @Pattern(regexp = RegexUtils.PHONE, message = "手机号码格式不正确")
    private String mobile;

    @ApiModelProperty("部门id")
    private Long deptId;

    @ApiModelProperty("机构id")
    @NotNull(message = "所属机构不能为空")
    private Long orgId;

    @ApiModelProperty("角色Id集合")
    @NotEmpty(message = "所属角色不能为空")
    private List<Long> roleId;

    @ApiModelProperty("是否启用 0锁定 1有效")
    @NotNull(message = "是否启用不能为空")
    @Range(min = 0, max = 1, message = "是否启用为0或1")
    private Integer status;

    @ApiModelProperty("性别")
    @DataMaps({
            @DataMap(name = "未知", value = "0"),
            @DataMap(name = "男", value = "1"),
            @DataMap(name = "女", value = "2")
    })
    private Integer sex;

    @ApiModelProperty("姓名")
    @NotBlank(message = "姓名不能为空")
    @Pattern(regexp = RegexUtils.REAL_NAME, message = "姓名格式不正确")
    private String realName;

    @ApiModelProperty("生日")
    @NotNull(message = "生日不能为空")
    @DateFormat("yyyy-MM-dd")
    private ZonedDateTime birthday;

    @ApiModelProperty("邮箱")
    private String email;

    @ApiModelProperty(value = "乐观锁版本")
    private Long version;

}
